package com.xinkao.example;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author: LXF
 * @description: SpringBoot启动类
 * @date: 2017/10/24 11:55
 */
@SpringBootApplication
@MapperScan("com.xinkao.example.dao")
public class MyApplication extends SpringBootServletInitializer {

	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext application = SpringApplication.run(MyApplication.class, args);
		Environment env = application.getEnvironment();

		String ip = InetAddress.getLocalHost().getHostAddress();
		String port = env.getProperty("server.port");
//		String path = env.getProperty("server.servlet.context-path");
		System.out.println("\n----------------------------------------------------------\n\t" +
				"Application xk_single_example is running! Access URLs:\n\t" +
				"Local: \t\thttp://localhost:" + port +  "/\n\t" +
				"External: \thttp://" + ip + ":" + port +  "/\n\t" +
				"Swagger: \thttp://localhost:" + port +  "/swagger-ui.html\n" +
				"----------------------------------------------------------");
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		// 注意这里要指向原先用main方法执行的Application启动类
		return builder.sources(MyApplication.class);
	}
}
